package demo3;

public class Computer {
    public void open() {
        System.out.println("开机");
    }
    public void close() {
        System.out.println("关机");
    }

    //所有的USB设备在电脑上是不是都可以使用吗
    public void useDevice(IUSB usb) {//向上转型
        usb.openDecice();
        if (usb instanceof Mouse) {
            Mouse mouse = (Mouse) usb;//向下转型
            mouse.click();
        }else if (usb instanceof KeyBoard) {
            KeyBoard keyBoard = (KeyBoard) usb;
            keyBoard.input();
        }
        usb.closeDecice();
    }
}
